package org.mathison.sayhello.spring;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SayHello {

	private IPerson person;
	public void setPerson(IPerson person) {
		this.person = person;
	}
	public IPerson getPerson() {
		return person;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		IPerson person = null;
		try {
			ApplicationContext context =
			    new ClassPathXmlApplicationContext(new String[] {"beans.xml"});
			
			SayHello app = (SayHello) context.getBean("app", SayHello.class);
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			person = app.getPerson();
			System.out.print("name ->");
			person.setName(reader.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("Hello " + person.getName());
	}

}
